"use client"

import * as React from "react"
import {
    BookOpen,
    Frame,
    GalleryVerticalEnd, LogIn, LogOut,
    Map,
    PieChart,
    Settings2,
    SquareTerminal,
} from "lucide-react"

import {NavMain} from "@/components/nav-main"
import {NavProjects} from "@/components/nav-projects"
import {NavUser} from "@/components/nav-user"
import {
    Sidebar,
    SidebarContent,
    SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem,
    SidebarRail,
} from "@/components/ui/sidebar"
import {useAuth} from "@/components/authProvider";
import BrandLink from "@/components/layout/BrandLink";
import Link from "next/link";

// This is sample data.
const data = {
    user: {
        name: "shadcn",
        email: "m@example.com",
        avatar: "/avatars/shadcn.jpg",
    },
    teams: [
        {
            name: "Acme Inc",
            logo: GalleryVerticalEnd,
            plan: "Enterprise",
        }
    ],
    navMain: [
        {
            title: "元数据管理",
            url: "#",
            icon: SquareTerminal,
            isActive: true,
            items: [
                {
                    title: "技术元数据",
                    url: "#",
                },
                {
                    title: "业务元数据",
                    url: "#",
                },
                {
                    title: "管理元数据",
                    url: "#",
                },
            ],
        },
        {
            title: "数据治理规则管理",
            url: "#",
            icon: BookOpen,
            items: [
                {
                    title: "规则定义",
                    url: "#",
                },
                {
                    title: "规则分类",
                    url: "#",
                }
            ],
        },
        {
            title: "数据质量管理",
            url: "#",
            icon: Settings2,
            items: [
                {
                    title: "调度执行",
                    url: "#",
                },
                {
                    title: "质量评分",
                    url: "#",
                }
            ],
        },
    ],
    projects: [
        {
            name: "帮助文档",
            url: "#",
            icon: Frame,
        },
        {
            name: "统计分析",
            url: "#",
            icon: PieChart,
        },
        {
            name: "其他",
            url: "#",
            icon: Map,
        },
    ],
}

export function AppSidebar({
                               ...props
                           }) {
    const auth = useAuth();
    return (
        <Sidebar collapsible="icon" {...props}>
            <BrandLink displayName="大数据治理平台"/>
            <SidebarContent>
                <NavMain items={data.navMain}/>
                <NavProjects projects={data.projects}/>
            </SidebarContent>


            {auth.isAuthenticated ?
                <SidebarFooter>
                    <NavUser user={data.user}/>
                </SidebarFooter>
                : <>
                    <SidebarGroup>
                        <SidebarGroupContent>
                            <SidebarMenu>
                                <SidebarMenuItem>
                                    <SidebarMenuButton>
                                        <LogIn/>
                                        <Link href="/login">
                                            登录
                                        </Link>
                                    </SidebarMenuButton>
                                </SidebarMenuItem>
                            </SidebarMenu>
                        </SidebarGroupContent>
                    </SidebarGroup>
                </>
            }
            <SidebarRail/>
        </Sidebar>
    );
}
